home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / winsockc.zip / WINSOCK.H < prev    next >
C/C++ Source or Header  |  1993-05-18  |  30KB  |  850 lines

  1. /* WINSOCK.H--definitions to be used with the WINSOCK.DLL
  2.  *
  3.  * This header file corresponds to version 1.1 of the Windows Sockets
  4.  * specification.
  5.  *
  6.  * This file includes parts which are Copyright (c) 1982-1986 Regents
  7.  * of the University of California.  All rights reserved.  The
  8.  * Berkeley Software License Agreement specifies the terms and
  9.  * conditions for redistribution.
  10.  *
  11.  * Change log:
  12.  *
  13.  * Fri Apr 23 16:31:01 1993  Mark Towfiq  (towfiq@Microdyne.COM)
  14.  *    New version from David Treadwell which adds extern "C" around
  15.  *    __WSAFDIsSet() and removes "const" from buf param of
  16.  *    WSAAsyncGetHostByAddr().  Added change log.
  17.  *
  18.  * Sat May 15 10:55:00 1993 David Treadwell (davidtr@microsoft.com)
  19.  *  Fix the IN_CLASSC macro to account for class-D multicasts.
  20.  *  Add AF_IPX == AF_NS.
  21.  *
  22.  */
  23.  
  24. #ifndef _WINSOCKAPI_
  25. #define _WINSOCKAPI_
  26.  
  27. /*
  28.  * Pull in WINDOWS.H if necessary
  29.  */
  30. #ifndef _INC_WINDOWS
  31. #include <windows.h>
  32. #endif /* _INC_WINDOWS */
  33.  
  34. /*
  35.  * Basic system type definitions, taken from the BSD file sys/types.h.
  36.  */
  37. typedef unsigned char   u_char;
  38. typedef unsigned short  u_short;
  39. typedef unsigned int    u_int;
  40. typedef unsigned long   u_long;
  41.  
  42. /*
  43.  * The new type to be used in all
  44.  * instances which refer to sockets.
  45.  */
  46. typedef u_int           SOCKET;
  47.  
  48. /*
  49.  * Select uses arrays of SOCKETs.  These macros manipulate such
  50.  * arrays.  FD_SETSIZE may be defined by the user before including
  51.  * this file, but the default here should be >= 64.
  52.  *
  53.  * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
  54.  * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
  55.  */
  56. #ifndef FD_SETSIZE
  57. #define FD_SETSIZE      64
  58. #endif /* FD_SETSIZE */
  59.  
  60. typedef struct fd_set {
  61.         u_short fd_count;               /* how many are SET? */
  62.         SOCKET  fd_array[FD_SETSIZE];   /* an array of SOCKETs */
  63. } fd_set;
  64.  
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif
  68.  
  69. extern int PASCAL FAR __WSAFDIsSet(SOCKET, fd_set FAR *);
  70.  
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74.  
  75. #define FD_CLR(fd, set) do { \
  76.     u_int __i; \
  77.     for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
  78.         if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \
  79.             while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
  80.                 ((fd_set FAR *)(set))->fd_array[__i] = \
  81.                     ((fd_set FAR *)(set))->fd_array[__i+1]; \
  82.                 __i++; \
  83.             } \
  84.             ((fd_set FAR *)(set))->fd_count--; \
  85.             break; \
  86.         } \
  87.     } \
  88. } while(0)
  89.  
  90. #define FD_SET(fd, set) do { \
  91.     if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
  92.         ((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=fd;\
  93. } while(0)
  94.  
  95. #define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)
  96.  
  97. #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)fd, (fd_set FAR *)set)
  98.  
  99. /*
  100.  * Structure used in select() call, taken from the BSD file sys/time.h.
  101.  */
  102. struct timeval {
  103.         long    tv_sec;         /* seconds */
  104.         long    tv_usec;        /* and microseconds */
  105. };
  106.  
  107. /*
  108.  * Operations on timevals.
  109.  *
  110.  * NB: timercmp does not work for >= or <=.
  111.  */
  112. #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
  113. #define timercmp(tvp, uvp, cmp) \
  114.         ((tvp)->tv_sec cmp (uvp)->tv_sec || \
  115.          (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
  116. #define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
  117.  
  118. /*
  119.  * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
  120.  *
  121.  *
  122.  * Ioctl's have the command encoded in the lower word,
  123.  * and the size of any in or out parameters in the upper
  124.  * word.  The high 2 bits of the upper word are used
  125.  * to encode the in/out status of the parameter; for now
  126.  * we restrict parameters to at most 128 bytes.
  127.  */
  128. #define IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
  129. #define IOC_VOID        0x20000000      /* no parameters */
  130. #define IOC_OUT         0x40000000      /* copy out parameters */
  131. #define IOC_IN          0x80000000      /* copy in parameters */
  132. #define IOC_INOUT       (IOC_IN|IOC_OUT)
  133.                                         /* 0x20000000 distinguishes new &
  134.                                            old ioctl's */
  135. #define _IO(x,y)        (IOC_VOID|(x<<8)|y)
  136.  
  137. #define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  138.  
  139. #define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  140.  
  141. #define FIONREAD    _IOR('f', 127, u_long) /* get # bytes to read */
  142. #define FIONBIO     _IOW('f', 126, u_long) /* set/clear non-blocking i/o */
  143. #define FIOASYNC    _IOW('f', 125, u_long) /* set/clear async i/o */
  144.  
  145. /* Socket I/O Controls */
  146. #define SIOCSHIWAT  _IOW('s',  0, u_long)  /* set high watermark */
  147. #define SIOCGHIWAT  _IOR('s',  1, u_long)  /* get high watermark */
  148. #define SIOCSLOWAT  _IOW('s',  2, u_long)  /* set low watermark */
  149. #define SIOCGLOWAT  _IOR('s',  3, u_long)  /* get low watermark */
  150. #define SIOCATMARK  _IOR('s',  7, u_long)  /* at oob mark? */
  151.  
  152. /*
  153.  * Structures returned by network data base library, taken from the
  154.  * BSD file netdb.h.  All addresses are supplied in host order, and
  155.  * returned in network order (suitable for use in system calls).
  156.  */
  157.  
  158. struct  hostent {
  159.         char    FAR * h_name;           /* official name of host */
  160.         char    FAR * FAR * h_aliases;  /* alias list */
  161.         short   h_addrtype;             /* host address type */
  162.         short   h_length;               /* length of address */
  163.         char    FAR * FAR * h_addr_list; /* list of addresses */
  164. #define h_addr  h_addr_list[0]          /* address, for backward compat */
  165. };
  166.  
  167. /*
  168.  * It is assumed here that a network number
  169.  * fits in 32 bits.
  170.  */
  171. struct  netent {
  172.         char    FAR * n_name;           /* official name of net */
  173.         char    FAR * FAR * n_aliases;  /* alias list */
  174.         short   n_addrtype;             /* net address type */
  175.         u_long  n_net;                  /* network # */
  176. };
  177.  
  178. struct  servent {
  179.         char    FAR * s_name;           /* official service name */
  180.         char    FAR * FAR * s_aliases;  /* alias list */
  181.         short   s_port;                 /* port # */
  182.         char    FAR * s_proto;          /* protocol to use */
  183. };
  184.  
  185. struct  protoent {
  186.         char    FAR * p_name;           /* official protocol name */
  187.         char    FAR * FAR * p_aliases;  /* alias list */
  188.         short   p_proto;                /* protocol # */
  189. };
  190.  
  191. /*
  192.  * Constants and structures defined by the internet system,
  193.  * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
  194.  */
  195.  
  196. /*
  197.  * Protocols
  198.  */
  199. #define IPPROTO_IP              0               /* dummy for IP */
  200. #define IPPROTO_ICMP            1               /* control message protocol */
  201. #define IPPROTO_GGP             2               /* gateway^2 (deprecated) */
  202. #define IPPROTO_TCP             6               /* tcp */
  203. #define IPPROTO_PUP             12              /* pup */
  204. #define IPPROTO_UDP             17              /* user datagram protocol */
  205. #define IPPROTO_IDP             22              /* xns idp */
  206. #define IPPROTO_ND              77              /* UNOFFICIAL net disk proto */
  207.  
  208. #define IPPROTO_RAW             255             /* raw IP packet */
  209. #define IPPROTO_MAX             256
  210.  
  211. /*
  212.  * Port/socket numbers: network standard functions
  213.  */
  214. #define IPPORT_ECHO             7
  215. #define IPPORT_DISCARD          9
  216. #define IPPORT_SYSTAT           11
  217. #define IPPORT_DAYTIME          13
  218. #define IPPORT_NETSTAT          15
  219. #define IPPORT_FTP              21
  220. #define IPPORT_TELNET           23
  221. #define IPPORT_SMTP             25
  222. #define IPPORT_TIMESERVER       37
  223. #define IPPORT_NAMESERVER       42
  224. #define IPPORT_WHOIS            43
  225. #define IPPORT_MTP              57
  226.  
  227. /*
  228.  * Port/socket numbers: host specific functions
  229.  */
  230. #define IPPORT_TFTP             69
  231. #define IPPORT_RJE              77
  232. #define IPPORT_FINGER           79
  233. #define IPPORT_TTYLINK          87
  234. #define IPPORT_SUPDUP           95
  235.  
  236. /*
  237.  * UNIX TCP sockets
  238.  */
  239. #define IPPORT_EXECSERVER       512
  240. #define IPPORT_LOGINSERVER      513
  241. #define IPPORT_CMDSERVER        514
  242. #define IPPORT_EFSSERVER        520
  243.  
  244. /*
  245.  * UNIX UDP sockets
  246.  */
  247. #define IPPORT_BIFFUDP          512
  248. #define IPPORT_WHOSERVER        513
  249. #define IPPORT_ROUTESERVER      520
  250.                                         /* 520+1 also used */
  251.  
  252. /*
  253.  * Ports < IPPORT_RESERVED are reserved for
  254.  * privileged processes (e.g. root).
  255.  */
  256. #define IPPORT_RESERVED         1024
  257.  
  258. /*
  259.  * Link numbers
  260.  */
  261. #define IMPLINK_IP              155
  262. #define IMPLINK_LOWEXPER        156
  263. #define IMPLINK_HIGHEXPER       158
  264.  
  265. /*
  266.  * Internet address (old style... should be updated)
  267.  */
  268. struct in_addr {
  269.         union {
  270.                 struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
  271.                 struct { u_short s_w1,s_w2; } S_un_w;
  272.                 u_long S_addr;
  273.         } S_un;
  274. #define s_addr  S_un.S_addr
  275.                                 /* can be used for most tcp & ip code */
  276. #define s_host  S_un.S_un_b.s_b2
  277.                                 /* host on imp */
  278. #define s_net   S_un.S_un_b.s_b1
  279.                                 /* network */
  280. #define s_imp   S_un.S_un_w.s_w2
  281.                                 /* imp */
  282. #define s_impno S_un.S_un_b.s_b4
  283.                                 /* imp # */
  284. #define s_lh    S_un.S_un_b.s_b3
  285.                                 /* logical host */
  286. };
  287.  
  288. /*
  289.  * Definitions of bits in internet address integers.
  290.  * On subnets, the decomposition of addresses to host and net parts
  291.  * is done according to subnet mask, not the masks here.
  292.  */
  293. #define IN_CLASSA(i)            (((long)(i) & 0x80000000) == 0)
  294. #define IN_CLASSA_NET           0xff000000
  295. #define IN_CLASSA_NSHIFT        24
  296. #define IN_CLASSA_HOST          0x00ffffff
  297. #define IN_CLASSA_MAX           128
  298.  
  299. #define IN_CLASSB(i)            (((long)(i) & 0xc0000000) == 0x80000000)
  300. #define IN_CLASSB_NET           0xffff0000
  301. #define IN_CLASSB_NSHIFT        16
  302. #define IN_CLASSB_HOST          0x0000ffff
  303. #define IN_CLASSB_MAX           65536
  304.  
  305. #define IN_CLASSC(i)            (((long)(i) & 0xe0000000) == 0xc0000000)
  306. #define IN_CLASSC_NET           0xffffff00
  307. #define IN_CLASSC_NSHIFT        8
  308. #define IN_CLASSC_HOST          0x000000ff
  309.  
  310. #define INADDR_ANY              (u_long)0x00000000
  311. #define INADDR_LOOPBACK         0x7f000001
  312. #define INADDR_BROADCAST        (u_long)0xffffffff    
  313. #define INADDR_NONE             0xffffffff
  314.  
  315. /*
  316.  * Socket address, internet style.
  317.  */
  318. struct sockaddr_in {
  319.         short   sin_family;
  320.         u_short sin_port;
  321.         struct  in_addr sin_addr;
  322.         char    sin_zero[8];
  323. };
  324.  
  325. #define WSADESCRIPTION_LEN      256
  326. #define WSASYS_STATUS_LEN       128
  327.  
  328. typedef struct WSAData {
  329.         WORD                    wVersion;
  330.         WORD                    wHighVersion;
  331.         char                    szDescription[WSADESCRIPTION_LEN+1];
  332.         char                    szSystemStatus[WSASYS_STATUS_LEN+1];
  333.         unsigned short          iMaxSockets;
  334.         unsigned short          iMaxUdpDg;
  335.         char FAR *              lpVendorInfo;
  336. } WSADATA;
  337.  
  338. typedef WSADATA FAR *LPWSADATA;
  339.  
  340. /*
  341.  * Options for use with [gs]etsockopt at the IP level.
  342.  */
  343. #define IP_OPTIONS      1               /* set/get IP per-packet options */
  344.  
  345. /*
  346.  * Definitions related to sockets: types, address families, options,
  347.  * taken from the BSD file sys/socket.h.
  348.  */
  349.  
  350. /*
  351.  * This is used instead of -1, since the
  352.  * SOCKET type is unsigned.
  353.  */
  354. #define INVALID_SOCKET  (SOCKET)(~0)
  355. #define SOCKET_ERROR            (-1)
  356.  
  357. /*
  358.  * Types
  359.  */
  360. #define SOCK_STREAM     1               /* stream socket */
  361. #define SOCK_DGRAM      2               /* datagram socket */
  362. #define SOCK_RAW        3               /* raw-protocol interface */
  363. #define SOCK_RDM        4               /* reliably-delivered message */
  364. #define SOCK_SEQPACKET  5               /* sequenced packet stream */
  365.  
  366. /*
  367.  * Option flags per-socket.
  368.  */
  369. #define SO_DEBUG        0x0001          /* turn on debugging info recording */
  370. #define SO_ACCEPTCONN   0x0002          /* socket has had listen() */
  371. #define SO_REUSEADDR    0x0004          /* allow local address reuse */
  372. #define SO_KEEPALIVE    0x0008          /* keep connections alive */
  373. #define SO_DONTROUTE    0x0010          /* just use interface addresses */
  374. #define SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
  375. #define SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
  376. #define SO_LINGER       0x0080          /* linger on close if data present */
  377. #define SO_OOBINLINE    0x0100          /* leave received OOB data in line */
  378.  
  379. #define SO_DONTLINGER   (u_int)(~SO_LINGER)
  380.  
  381. /*
  382.  * Additional options.
  383.  */
  384. #define SO_SNDBUF       0x1001          /* send buffer size */
  385. #define SO_RCVBUF       0x1002          /* receive buffer size */
  386. #define SO_SNDLOWAT     0x1003          /* send low-water mark */
  387. #define SO_RCVLOWAT     0x1004          /* receive low-water mark */
  388. #define SO_SNDTIMEO     0x1005          /* send timeout */
  389. #define SO_RCVTIMEO     0x1006          /* receive timeout */
  390. #define SO_ERROR        0x1007          /* get error status and clear */
  391. #define SO_TYPE         0x1008          /* get socket type */
  392.  
  393. /*
  394.  * TCP options.
  395.  */
  396. #define TCP_NODELAY     0x0001
  397.  
  398. /*
  399.  * Address families.
  400.  */
  401. #define AF_UNSPEC       0               /* unspecified */
  402. #define AF_UNIX         1               /* local to host (pipes, portals) */
  403. #define AF_INET         2               /* internetwork: UDP, TCP, etc. */
  404. #define AF_IMPLINK      3               /* arpanet imp addresses */
  405. #define AF_PUP          4               /* pup protocols: e.g. BSP */
  406. #define AF_CHAOS        5               /* mit CHAOS protocols */
  407. #define AF_NS           6               /* XEROX NS protocols */
  408. #define AF_IPX          6               /* IPX and SPX */
  409. #define AF_ISO          7               /* ISO protocols */
  410. #define AF_OSI          AF_ISO          /* OSI is ISO */
  411. #define AF_ECMA         8               /* european computer manufacturers */
  412. #define AF_DATAKIT      9               /* datakit protocols */
  413. #define AF_CCITT        10              /* CCITT protocols, X.25 etc */
  414. #define AF_SNA          11              /* IBM SNA */
  415. #define AF_DECnet       12              /* DECnet */
  416. #define AF_DLI          13              /* Direct data link interface */
  417. #define AF_LAT          14              /* LAT */
  418. #define AF_HYLINK       15              /* NSC Hyperchannel */
  419. #define AF_APPLETALK    16              /* AppleTalk */
  420. #define AF_NETBIOS      17              /* NetBios-style addresses */
  421.  
  422. #define AF_MAX          18
  423.  
  424. /*
  425.  * Structure used by kernel to store most
  426.  * addresses.
  427.  */
  428. struct sockaddr {
  429.         u_short sa_family;              /* address family */
  430.         char    sa_data[14];            /* up to 14 bytes of direct address */
  431. };
  432.  
  433. /*
  434.  * Structure used by kernel to pass protocol
  435.  * information in raw sockets.
  436.  */
  437. struct sockproto {
  438.         u_short sp_family;              /* address family */
  439.         u_short sp_protocol;            /* protocol */
  440. };
  441.  
  442. /*
  443.  * Protocol families, same as address families for now.
  444.  */
  445. #define PF_UNSPEC       AF_UNSPEC
  446. #define PF_UNIX         AF_UNIX
  447. #define PF_INET         AF_INET
  448. #define PF_IMPLINK      AF_IMPLINK
  449. #define PF_PUP          AF_PUP
  450. #define PF_CHAOS        AF_CHAOS
  451. #define PF_NS           AF_NS
  452. #define PF_IPX          AF_IPX
  453. #define PF_ISO          AF_ISO
  454. #define PF_OSI          AF_OSI
  455. #define PF_ECMA         AF_ECMA
  456. #define PF_DATAKIT      AF_DATAKIT
  457. #define PF_CCITT        AF_CCITT
  458. #define PF_SNA          AF_SNA
  459. #define PF_DECnet       AF_DECnet
  460. #define PF_DLI          AF_DLI
  461. #define PF_LAT          AF_LAT
  462. #define PF_HYLINK       AF_HYLINK
  463. #define PF_APPLETALK    AF_APPLETALK
  464.  
  465. #define PF_MAX          AF_MAX
  466.  
  467. /*
  468.  * Structure used for manipulating linger option.
  469.  */
  470. struct  linger {
  471.         u_short l_onoff;                /* option on/off */
  472.         u_short l_linger;               /* linger time */
  473. };
  474.  
  475. /*
  476.  * Level number for (get/set)sockopt() to apply to socket itself.
  477.  */
  478. #define SOL_SOCKET      0xffff          /* options for socket level */
  479.  
  480. /*
  481.  * Maximum queue length specifiable by listen.
  482.  */
  483. #define SOMAXCONN       5
  484.  
  485. #define MSG_OOB         0x1             /* process out-of-band data */
  486. #define MSG_PEEK        0x2             /* peek at incoming message */
  487. #define MSG_DONTROUTE   0x4             /* send without using routing tables */
  488.  
  489. #define MSG_MAXIOVLEN   16
  490.  
  491. /*
  492.  * Define constant based on rfc883, used by gethostbyxxxx() calls.
  493.  */
  494. #define MAXGETHOSTSTRUCT        1024
  495.  
  496. /*
  497.  * Define flags to be used with the WSAAsyncSelect() call.
  498.  */
  499. #define FD_READ         0x01
  500. #define FD_WRITE        0x02
  501. #define FD_OOB          0x04
  502. #define FD_ACCEPT       0x08
  503. #define FD_CONNECT      0x10
  504. #define FD_CLOSE        0x20
  505.  
  506. /*
  507.  * All Windows Sockets error constants are biased by WSABASEERR from
  508.  * the "normal"
  509.  */
  510. #define WSABASEERR              10000
  511. /*
  512.  * Windows Sockets definitions of regular Microsoft C error constants
  513.  */
  514. #define WSAEINTR                (WSABASEERR+4)
  515. #define WSAEBADF                (WSABASEERR+9)
  516. #define WSAEACCES               (WSABASEERR+13)
  517. #define WSAEFAULT               (WSABASEERR+14)
  518. #define WSAEINVAL               (WSABASEERR+22)
  519. #define WSAEMFILE               (WSABASEERR+24)
  520.  
  521. /*
  522.  * Windows Sockets definitions of regular Berkeley error constants
  523.  */
  524. #define WSAEWOULDBLOCK          (WSABASEERR+35)
  525. #define WSAEINPROGRESS          (WSABASEERR+36)
  526. #define WSAEALREADY             (WSABASEERR+37)
  527. #define WSAENOTSOCK             (WSABASEERR+38)
  528. #define WSAEDESTADDRREQ         (WSABASEERR+39)
  529. #define WSAEMSGSIZE             (WSABASEERR+40)
  530. #define WSAEPROTOTYPE           (WSABASEERR+41)
  531. #define WSAENOPROTOOPT          (WSABASEERR+42)
  532. #define WSAEPROTONOSUPPORT      (WSABASEERR+43)
  533. #define WSAESOCKTNOSUPPORT      (WSABASEERR+44)
  534. #define WSAEOPNOTSUPP           (WSABASEERR+45)
  535. #define WSAEPFNOSUPPORT         (WSABASEERR+46)
  536. #define WSAEAFNOSUPPORT         (WSABASEERR+47)
  537. #define WSAEADDRINUSE           (WSABASEERR+48)
  538. #define WSAEADDRNOTAVAIL        (WSABASEERR+49)
  539. #define WSAENETDOWN             (WSABASEERR+50)
  540. #define WSAENETUNREACH          (WSABASEERR+51)
  541. #define WSAENETRESET            (WSABASEERR+52)
  542. #define WSAECONNABORTED         (WSABASEERR+53)
  543. #define WSAECONNRESET           (WSABASEERR+54)
  544. #define WSAENOBUFS              (WSABASEERR+55)
  545. #define WSAEISCONN              (WSABASEERR+56)
  546. #define WSAENOTCONN             (WSABASEERR+57)
  547. #define WSAESHUTDOWN            (WSABASEERR+58)
  548. #define WSAETOOMANYREFS         (WSABASEERR+59)
  549. #define WSAETIMEDOUT            (WSABASEERR+60)
  550. #define WSAECONNREFUSED         (WSABASEERR+61)
  551. #define WSAELOOP                (WSABASEERR+62)
  552. #define WSAENAMETOOLONG         (WSABASEERR+63)
  553. #define WSAEHOSTDOWN            (WSABASEERR+64)
  554. #define WSAEHOSTUNREACH         (WSABASEERR+65)
  555. #define WSAENOTEMPTY            (WSABASEERR+66)
  556. #define WSAEPROCLIM             (WSABASEERR+67)
  557. #define WSAEUSERS               (WSABASEERR+68)
  558. #define WSAEDQUOT               (WSABASEERR+69)
  559. #define WSAESTALE               (WSABASEERR+70)
  560. #define WSAEREMOTE              (WSABASEERR+71)
  561.  
  562. /*
  563.  * Extended Windows Sockets error constant definitions
  564.  */
  565. #define WSASYSNOTREADY          (WSABASEERR+91)
  566. #define WSAVERNOTSUPPORTED      (WSABASEERR+92)
  567. #define WSANOTINITIALISED       (WSABASEERR+93)
  568.  
  569. /*
  570.  * Error return codes from gethostbyname() and gethostbyaddr()
  571.  * (when using the resolver). Note that these errors are
  572.  * retrieved via WSAGetLastError() and must therefore follow
  573.  * the rules for avoiding clashes with error numbers from
  574.  * specific implementations or language run-time systems.
  575.  * For this reason the codes are based at WSABASEERR+1001.
  576.  * Note also that [WSA]NO_ADDRESS is defined only for
  577.  * compatibility purposes.
  578.  */
  579.  
  580. #define h_errno         WSAGetLastError()
  581.  
  582. /* Authoritative Answer: Host not found */
  583. #define WSAHOST_NOT_FOUND       (WSABASEERR+1001)
  584. #define HOST_NOT_FOUND          WSAHOST_NOT_FOUND
  585.  
  586. /* Non-Authoritative: Host not found, or SERVERFAIL */
  587. #define WSATRY_AGAIN            (WSABASEERR+1002)
  588. #define TRY_AGAIN               WSATRY_AGAIN
  589.  
  590. /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  591. #define WSANO_RECOVERY          (WSABASEERR+1003)
  592. #define NO_RECOVERY             WSANO_RECOVERY
  593.  
  594. /* Valid name, no data record of requested type */
  595. #define WSANO_DATA              (WSABASEERR+1004)
  596. #define NO_DATA                 WSANO_DATA
  597.  
  598. /* no address, look for MX record */
  599. #define WSANO_ADDRESS           WSANO_DATA
  600. #define NO_ADDRESS              WSANO_ADDRESS
  601.  
  602. /*
  603.  * Windows Sockets errors redefined as regular Berkeley error constants
  604.  */
  605. #define EWOULDBLOCK             WSAEWOULDBLOCK
  606. #define EINPROGRESS             WSAEINPROGRESS
  607. #define EALREADY                WSAEALREADY
  608. #define ENOTSOCK                WSAENOTSOCK
  609. #define EDESTADDRREQ            WSAEDESTADDRREQ
  610. #define EMSGSIZE                WSAEMSGSIZE
  611. #define EPROTOTYPE              WSAEPROTOTYPE
  612. #define ENOPROTOOPT             WSAENOPROTOOPT
  613. #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
  614. #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
  615. #define EOPNOTSUPP              WSAEOPNOTSUPP
  616. #define EPFNOSUPPORT            WSAEPFNOSUPPORT
  617. #define EAFNOSUPPORT            WSAEAFNOSUPPORT
  618. #define EADDRINUSE              WSAEADDRINUSE
  619. #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
  620. #define ENETDOWN                WSAENETDOWN
  621. #define ENETUNREACH             WSAENETUNREACH
  622. #define ENETRESET               WSAENETRESET
  623. #define ECONNABORTED            WSAECONNABORTED
  624. #define ECONNRESET              WSAECONNRESET
  625. #define ENOBUFS                 WSAENOBUFS
  626. #define EISCONN                 WSAEISCONN
  627. #define ENOTCONN                WSAENOTCONN
  628. #define ESHUTDOWN               WSAESHUTDOWN
  629. #define ETOOMANYREFS            WSAETOOMANYREFS
  630. #define ETIMEDOUT               WSAETIMEDOUT
  631. #define ECONNREFUSED            WSAECONNREFUSED
  632. #define ELOOP                   WSAELOOP
  633. #define ENAMETOOLONG            WSAENAMETOOLONG
  634. #define EHOSTDOWN               WSAEHOSTDOWN
  635. #define EHOSTUNREACH            WSAEHOSTUNREACH
  636. #define ENOTEMPTY               WSAENOTEMPTY
  637. #define EPROCLIM                WSAEPROCLIM
  638. #define EUSERS                  WSAEUSERS
  639. #define EDQUOT                  WSAEDQUOT
  640. #define ESTALE                  WSAESTALE
  641. #define EREMOTE                 WSAEREMOTE
  642.  
  643. /* Socket function prototypes */
  644.  
  645. #ifdef __cplusplus
  646. extern "C" {
  647. #endif
  648.  
  649. SOCKET PASCAL FAR accept (SOCKET s, struct sockaddr FAR *addr,
  650.                           int FAR *addrlen);
  651.  
  652. int PASCAL FAR bind (SOCKET s, const struct sockaddr FAR *addr, int namelen);
  653.  
  654. int PASCAL FAR closesocket (SOCKET s);
  655.  
  656. int PASCAL FAR connect (SOCKET s, const struct sockaddr FAR *name, int namelen);
  657.  
  658. int PASCAL FAR ioctlsocket (SOCKET s, long cmd, u_long FAR *argp);
  659.  
  660. int PASCAL FAR getpeername (SOCKET s, struct sockaddr FAR *name,
  661.                             int FAR * namelen);
  662.  
  663. int PASCAL FAR getsockname (SOCKET s, struct sockaddr FAR *name,
  664.                             int FAR * namelen);
  665.  
  666. int PASCAL FAR getsockopt (SOCKET s, int level, int optname,
  667.                            char FAR * optval, int FAR *optlen);
  668.  
  669. u_long PASCAL FAR htonl (u_long hostlong);
  670.  
  671. u_short PASCAL FAR htons (u_short hostshort);
  672.  
  673. unsigned long PASCAL FAR inet_addr (const char FAR * cp);
  674.  
  675. char FAR * PASCAL FAR inet_ntoa (struct in_addr in);
  676.  
  677. int PASCAL FAR listen (SOCKET s, int backlog);
  678.  
  679. u_long PASCAL FAR ntohl (u_long netlong);
  680.  
  681. u_short PASCAL FAR ntohs (u_short netshort);
  682.  
  683. int PASCAL FAR recv (SOCKET s, char FAR * buf, int len, int flags);
  684.  
  685. int PASCAL FAR recvfrom (SOCKET s, char FAR * buf, int len, int flags,
  686.                          struct sockaddr FAR *from, int FAR * fromlen);
  687.  
  688. int PASCAL FAR select (int nfds, fd_set FAR *readfds, fd_set FAR *writefds,
  689.                        fd_set FAR *exceptfds, const struct timeval FAR *timeout);
  690.  
  691. int PASCAL FAR send (SOCKET s, const char FAR * buf, int len, int flags);
  692.  
  693. int PASCAL FAR sendto (SOCKET s, const char FAR * buf, int len, int flags,
  694.                        const struct sockaddr FAR *to, int tolen);
  695.  
  696. int PASCAL FAR setsockopt (SOCKET s, int level, int optname,
  697.                            const char FAR * optval, int optlen);
  698.  
  699. int PASCAL FAR shutdown (SOCKET s, int how);
  700.  
  701. SOCKET PASCAL FAR socket (int af, int type, int protocol);
  702.  
  703. /* Database function prototypes */
  704.  
  705. struct hostent FAR * PASCAL FAR gethostbyaddr(const char FAR * addr,
  706.                                               int len, int type);
  707.  
  708. struct hostent FAR * PASCAL FAR gethostbyname(const char FAR * name);
  709.  
  710. int PASCAL FAR gethostname (char FAR * name, int namelen);
  711.  
  712. struct servent FAR * PASCAL FAR getservbyport(int port, const char FAR * proto);
  713.  
  714. struct servent FAR * PASCAL FAR getservbyname(const char FAR * name,
  715.                                               const char FAR * proto);
  716.  
  717. struct protoent FAR * PASCAL FAR getprotobynumber(int proto);
  718.  
  719. struct protoent FAR * PASCAL FAR getprotobyname(const char FAR * name);
  720.  
  721. /* Microsoft Windows Extension function prototypes */
  722.  
  723. int PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
  724.  
  725. int PASCAL FAR WSACleanup(void);
  726.  
  727. void PASCAL FAR WSASetLastError(int iError);
  728.  
  729. int PASCAL FAR WSAGetLastError(void);
  730.  
  731. BOOL PASCAL FAR WSAIsBlocking(void);
  732.  
  733. int PASCAL FAR WSAUnhookBlockingHook(void);
  734.  
  735. FARPROC PASCAL FAR WSASetBlockingHook(FARPROC lpBlockFunc);
  736.  
  737. int PASCAL FAR WSACancelBlockingCall(void);
  738.  
  739. HANDLE PASCAL FAR WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
  740.                                         const char FAR * name, 
  741.                                         const char FAR * proto,
  742.                                         char FAR * buf, int buflen);
  743.  
  744. HANDLE PASCAL FAR WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
  745.                                         const char FAR * proto, char FAR * buf,
  746.                                         int buflen);
  747.  
  748. HANDLE PASCAL FAR WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
  749.                                          const char FAR * name, char FAR * buf,
  750.                                          int buflen);
  751.  
  752. HANDLE PASCAL FAR WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
  753.                                            int number, char FAR * buf,
  754.                                            int buflen);
  755.  
  756. HANDLE PASCAL FAR WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
  757.                                         const char FAR * name, char FAR * buf,
  758.                                         int buflen);
  759.  
  760. HANDLE PASCAL FAR WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
  761.                                         const char FAR * addr, int len, int type,
  762.                                         char FAR * buf, int buflen);
  763.  
  764. int PASCAL FAR WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
  765.  
  766. int PASCAL FAR WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
  767.                                long lEvent);
  768.  
  769. #ifdef __cplusplus
  770. }
  771. #endif
  772.  
  773. /* Microsoft Windows Extended data types */
  774. typedef struct sockaddr SOCKADDR;
  775. typedef struct sockaddr *PSOCKADDR;
  776. typedef struct sockaddr FAR *LPSOCKADDR;
  777.  
  778. typedef struct sockaddr_in SOCKADDR_IN;
  779. typedef struct sockaddr_in *PSOCKADDR_IN;
  780. typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
  781.  
  782. typedef struct linger LINGER;
  783. typedef struct linger *PLINGER;
  784. typedef struct linger FAR *LPLINGER;
  785.  
  786. typedef struct in_addr IN_ADDR;
  787. typedef struct in_addr *PIN_ADDR;
  788. typedef struct in_addr FAR *LPIN_ADDR;
  789.  
  790. typedef struct fd_set FD_SET;
  791. typedef struct fd_set *PFD_SET;
  792. typedef struct fd_set FAR *LPFD_SET;
  793.  
  794. typedef struct hostent HOSTENT;
  795. typedef struct hostent *PHOSTENT;
  796. typedef struct hostent FAR *LPHOSTENT;
  797.  
  798. typedef struct servent SERVENT;
  799. typedef struct servent *PSERVENT;
  800. typedef struct servent FAR *LPSERVENT;
  801.  
  802. typedef struct protoent PROTOENT;
  803. typedef struct protoent *PPROTOENT;
  804. typedef struct protoent FAR *LPPROTOENT;
  805.  
  806. typedef struct timeval TIMEVAL;
  807. typedef struct timeval *PTIMEVAL;
  808. typedef struct timeval FAR *LPTIMEVAL;
  809.  
  810. /*
  811.  * Windows message parameter composition and decomposition
  812.  * macros.
  813.  *
  814.  * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
  815.  * when constructing the response to a WSAAsyncGetXByY() routine.
  816.  */
  817. #define WSAMAKEASYNCREPLY(buflen,error)     MAKELONG(buflen,error)
  818. /*
  819.  * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
  820.  * when constructing the response to WSAAsyncSelect().
  821.  */
  822. #define WSAMAKESELECTREPLY(event,error)     MAKELONG(event,error)
  823. /*
  824.  * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
  825.  * to extract the buffer length from the lParam in the response
  826.  * to a WSAGetXByY().
  827.  */
  828. #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  829. /*
  830.  * WSAGETASYNCERROR is intended for use by the Windows Sockets application
  831.  * to extract the error code from the lParam in the response
  832.  * to a WSAGetXByY().
  833.  */
  834. #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  835. /*
  836.  * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
  837.  * to extract the event code from the lParam in the response
  838.  * to a WSAAsyncSelect().
  839.  */
  840. #define WSAGETSELECTEVENT(lParam)           LOWORD(lParam)
  841. /*
  842.  * WSAGETSELECTERROR is intended for use by the Windows Sockets application
  843.  * to extract the error code from the lParam in the response
  844.  * to a WSAAsyncSelect().
  845.  */
  846. #define WSAGETSELECTERROR(lParam)           HIWORD(lParam)
  847.  
  848. #endif  /* _WINSOCKAPI_ */
  849.  
  850.